home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Include / FWExcept.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  3.5 KB  |  122 lines  |  [TEXT/MPS ]

  1. #ifndef FWEXCEPT_H
  2. #define FWEXCEPT_H
  3. //========================================================================================
  4. //
  5. //    File:                FWExcept.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef   FWCLAINF_H
  13. #include "FWClaInf.h"
  14. #endif
  15.  
  16. #ifndef FWPRIDEB_H
  17. #include "FWPriDeb.h"
  18. #endif
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. //========================================================================================
  25. // Exception classes definition and implementation macros
  26. //========================================================================================
  27.  
  28. #define FW_DECLARE_EXCEPTION(name) \
  29. public: \
  30.     FW_DECLARE_CLASS
  31.  
  32. #define FW_DEFINE_EXCEPTION_ROOT(name) \
  33.     FW_DEFINE_CLASS_M0(name)
  34.  
  35. #define FW_DEFINE_EXCEPTION(name, ancestor) \
  36.     FW_DEFINE_CLASS_M1(name, ancestor)
  37.  
  38. //========================================================================================
  39. // CLASS _FW_XException
  40. //========================================================================================
  41.  
  42. class FW_CLASS_ATTR _FW_XException
  43. {
  44. public:
  45.     virtual ~_FW_XException();
  46.     _FW_XException();
  47.  
  48.     size_t GetSize() const;
  49.         // Returns the size of this object, using info from its metaclass
  50.         // This method is not virtual, but will work correctly since PrivVirtualGetClassInfo is virtual.
  51.     
  52.     const char* GetClassName() const;
  53.         // Returns the class name of this object, as a string.
  54.         // This method is not virtual, but will work correctly since PrivVirtualGetClassInfo is virtual.
  55.  
  56.     virtual void Copy(void *p, size_t maxObjectSize) const;
  57.         // Copies this object.  This method does a bitwise copy, but subclasses
  58.         //   must override to perform a deep copy.
  59.  
  60. #ifndef FW_NATIVE_EXCEPTIONS    
  61.     int PrivIsKindOf(FW_ClassInfoPtr  aClass);
  62.         // Returns 1 if this object is a kind of aClass, i.e. same or subclass of aClass.
  63.         
  64.     void PrivDelete();
  65.         // Calls the virtual destructor, but does not attept to delete storage.
  66.  
  67. #endif // FW_NATIVE_EXCEPTIONS
  68.  
  69. #ifdef FW_DEBUG
  70.     short    fIsValid;
  71. #endif
  72.  
  73.     FW_DECLARE_EXCEPTION(_FW_XException)
  74.  
  75. public:
  76.     // these are provided to mask a bug in Borland C++ (it calls delete when
  77.     //    you just want to call the dtor, explicitly)
  78.     void* operator new(size_t size);
  79.     void operator delete(void* memory);
  80. };
  81.  
  82. //========================================================================================
  83. // CLASS _FW_XException inline functions
  84. //========================================================================================
  85.  
  86. inline size_t _FW_XException::GetSize() const
  87. {
  88.     FW_PRIV_ASSERT(fIsValid==1);
  89.     return PrivVirtualGetClassInfo()->GetInstanceSize();
  90. }
  91.  
  92. inline const char* _FW_XException::GetClassName() const
  93. {
  94.     FW_PRIV_ASSERT(fIsValid==1);
  95.     return PrivVirtualGetClassInfo()->GetClassName();
  96. }
  97.  
  98. #ifndef FW_NATIVE_EXCEPTIONS
  99.  
  100. inline void _FW_XException::PrivDelete()
  101. {
  102.     FW_PRIV_ASSERT(fIsValid==1);
  103. #ifdef _MPWCFRONT
  104.     // MPW CFront is not supported with this version of the code
  105.     FW_PRIV_ASSERT(FALSE);
  106.     // CFront is bizarre.  It won't allow the unscoped destructor name, but the scoped 
  107.     // name is dispatched virtually, even though ARM says scoped names are never virtual.
  108.     this->_FW_XException::~_FW_XException();
  109. #else
  110.     this->~_FW_XException();    // Virtual dispatch to object's destructor
  111. #endif
  112.     FW_PRIV_ASSERT(fIsValid == 0);
  113. }
  114.  
  115. #endif // FW_NATIVE_EXCEPTIONS
  116.  
  117. #if FW_LIB_EXPORT_PRAGMAS
  118. #pragma lib_export off
  119. #endif
  120.  
  121. #endif
  122.